﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DScheme.DancerClasses
{
    enum DancerPositionValues { PosX, PosY, Angle }
    enum DancerActionStates { NotStart, Executed, Done }

    abstract class DancerAction
    {
        public double StartTimeS;
        public double EndTimeS { get { return StartTimeS + MoveTimeS; } }
        public readonly double MoveTimeS;
        protected readonly Dancer dancer;

        /// <summary>статус выполнения действия</summary>
        public DancerActionStates State { get { return state; } }
        DancerActionStates state = DancerActionStates.NotStart;

        /// <summary>процент завершения действия (значение от 0 до 1)</summary>
        public double DoneValue { get { return doneVal; } }
        double doneVal = 0;

        /// <summary>список переменных, позиции, которые следует заполнить перед выполнением</summary>
        protected static List<DancerPositionValues> startSetValList = new List<DancerPositionValues>();

        public DancerAction(Dancer dancer, double startTimeS, double moveTimeS)
        {
            MoveTimeS = moveTimeS;
            StartTimeS = startTimeS;
            this.dancer = dancer;
        }

        public void Execute(double actTimeS)
        {
            doneVal = 0;
            if (actTimeS <= StartTimeS) return;
            if (State == DancerActionStates.Done) return;
            if (State == DancerActionStates.NotStart) ExecuteBeforeStart();

            if (actTimeS >= EndTimeS)
            {
                doneVal = 1;
                ExecuteDone();
                state = DancerActionStates.Done;
                return;
            }

            state = DancerActionStates.Executed;
            doneVal = (actTimeS - StartTimeS) / MoveTimeS;
            ExecuteAction(actTimeS);
        }

        protected abstract void ExecuteBeforeStart();

        /// <summary>выполнение действия</summary>
        /// <param name="actTimeS">время, пройденное от начала действа (сек)</param>
        protected abstract void ExecuteAction(double actTimeS);

        /// <summary>выполнение окончания действий</summary>
        protected abstract void ExecuteDone();

    }
}
